<CFQUERY NAME="qryCINLEAVEAPPSM" DATASOURCE="#client.company_dsn#">
	SELECT *
	FROM CINLEAVEAPPSM
	WHERE ROUTEID = '#GetRecord.ROUTEID#'
</CFQUERY>

<CFIF isDefined("qryCINLEAVEAPPSM.STAFFPID")>
	<CFIF GetEntry.STAFFPID NEQ "">
		<CFSET formPID = qryCINLEAVEAPPSM.STAFFPID>
	<CFELSE>
		<CFSET formPID = qryCINLEAVEAPPSM.PERSONNELIDNO>
	</CFIF>
<CFELSE>
	<CFSET formPID = qryCINLEAVEAPPSM.PERSONNELIDNO>
</CFIF>

<!--- replace the current personnelidno with staffpid if existing --->
<CFIF isDefined("qryCINLEAVEAPPSM.STAFFPID")>
	<CFIF GetEntry.STAFFPID NEQ "">
		<CFQUERY NAME="qryCINLEAVEAPPSM" DATASOURCE="#client.company_dsn#">
			UPDATE CINLEAVEAPPSM
			SET PERSONNELIDNO = '#formPID#'
			WHERE ROUTEID = '#GetRecord.ROUTEID#'
		</CFQUERY>
	</CFIF>
</CFIF>

